<?php

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap {

    protected function _initAutoloadModuleAdmin() {
        $autoloader = new Zend_Application_Module_Autoloader(array(
                    'namespace' => 'Admin',
                    'basePath' => APPLICATION_PATH . '/modules/admin',
                ));
        return $autoloader;
    }

    protected function _initView() {
        $view = new Zend_View();
//        $view->addHelperPath("ZendX/JQuery/View/Helper", "ZendX_JQuery_View_Helper");
        $view->headTitle('Rowaad Laservision Center');
        $view->addHelperPath('Golib/View/Helper', 'Golib_View_Helper_');
        $viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper(
                        'ViewRenderer'
        );
        $viewRenderer->setView($view);
        // Return it, so that it can be stored by the bootstrap
        return $view;
    }

    protected function _initLayout() {
        Zend_Layout::startMvc();
        $frontController = Zend_Controller_Front::getInstance();
        $frontController->registerPlugin(new Golib_Plugin_ModuleLayout());
    }

    protected function _initDoctrine() {


        $this->getApplication()->getAutoloader()
                ->pushAutoloader(array('Doctrine', 'autoload'));

        spl_autoload_register(array('Doctrine', 'modelsAutoload'));
        $manager = Doctrine_Manager::getInstance();

        $manager->setAttribute(Doctrine::ATTR_AUTOLOAD_TABLE_CLASSES, TRUE);
        $manager->setAttribute(Doctrine::ATTR_AUTO_ACCESSOR_OVERRIDE, TRUE);
        $manager->setAttribute(Doctrine::ATTR_MODEL_LOADING, Doctrine::MODEL_LOADING_CONSERVATIVE);

        $doctrineConfig = new Zend_Config_Ini(APPLICATION_PATH . "/configs/database.ini", 'development');

        Doctrine::loadModels($doctrineConfig->doctrine->models_path);


        $conn = Doctrine_Manager::connection($doctrineConfig->doctrine->dsn, 'doctrine');
        $conn->setAttribute(Doctrine::ATTR_USE_NATIVE_ENUM, TRUE);
        $conn->setCharset('utf8');
        $conn->setCollate('utf8_general_ci');
//                $res = Doctrine::generateModelsFromDb(
//                        $doctrineConfig->doctrine->models_path,
//                        array('doctrine'),
//                        array('generateTableClasses' => true));
//die("done");
        return $conn;
    }

    protected function _initRoute() {
        $frontController = Zend_Controller_Front::getInstance();
        $router = $frontController->getRouter();
        $router->removeDefaultRoutes();
        $router->setGlobalParam('lang', 'en');


        $router->addRoute(
                'base', new Zend_Controller_Router_Route('/',
                        array('lang' => 'en',
                            'module' => 'default',
                            'controller' => 'index',
                            'action' => 'index'
                        )
                )
        );
        $router->addRoute(
                'langindexcont', new Zend_Controller_Router_Route('/:lang/:controller/:action',
                        array('module' => 'default',
                            'lang' => 'en'
                        )
                )
        );

        $router->addRoute(
                'langindex', new Zend_Controller_Router_Route('/:lang',
                        array('lang' => 'en',
                            'module' => 'default',
                            'controller' => 'index',
                            'action' => 'index'
                        )
                )
        );

        $router->addRoute(
                'langcontroller', new Zend_Controller_Router_Route('/:lang/:controller',
                        array('lang' => 'en',
                            'module' => 'default',
                            'controller' => 'index',
                            'action' => 'index'
                        )
                )
        );

        $router->addRoute(
                'adminindex', new Zend_Controller_Router_Route('/admin', array('module' => 'admin',
                    'controller' => 'index',
                    'action' => 'index')));
        $router->addRoute(
                'admincontrolleraction', new Zend_Controller_Router_Route('/admin/:controller/:action', array('module' => 'admin',
                    'controller' => 'index',
                    'action' => 'index')));
        $router->addRoute(
                'admincontroller', new Zend_Controller_Router_Route('/admin/:controller', array('module' => 'admin',
                    'controller' => 'index',
                    'action' => 'index')));
    }
    
    
}

